package cn.glutnn.service.impl;

import cn.glutnn.entity.Result;
import cn.glutnn.mapper.FoodMapper;
import cn.glutnn.service.FoodService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import cn.glutnn.entity.Food;

/**
 * 食品表(Food)表服务实现类
 *
 * @author msh
 * @since 2024-12-10 22:36:26
 */
@Service("foodService")
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

    @Override
    public Result updateStock(Integer foodId, Integer quantity) {
        Food food = getById(foodId);
        if (food != null) {
            if (food.getStock() + quantity < 0) {
                return Result.error("库存不能小于零");
            }
            food.setStock(food.getStock() + quantity);
            updateById(food);
        }
        return Result.success();
    }
}

